<template>
  <div>
    <!-- load上拉时出 -->
    <van-list
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="onLoad"
    >
      <van-cell
        @click="details(item.art_id)"
        v-for="item in list"
        :key="item.art_id"
      >
        <!-- 插槽 -->
        <template>
          <!-- 标题部分 -->
          <div>{{ item.title }}</div>
          <!-- 图片部分 -->
          <van-grid :border="false" :column-num="item.cover.type">
            <van-grid-item v-for="(val, inx) in item.cover.images" :key="inx">
              <van-image class="pic" :src="val" />
            </van-grid-item>
          </van-grid>
          <!-- 下面的评论,时间页面 -->
          <div class="date">
            <span>{{ item.aut_name }}</span>
            <span>{{ item.comm_count }}评论</span>
            <span class="date">发布:{{ item.pubdate | relvTime }}</span>
          </div>
        </template>
      </van-cell>
    </van-list>
  </div>
</template>

<script>
import { articleListAPI } from '@/Api'

export default {
  props: ['channel_id'],
  data () {
    return {
      list: [],
      loading: false,
      finished: false,
      timestamp: Date.now()
    }
  },
  methods: {
    details (id) {
      this.$router.push({
        name: 'details',
        query: {
          article_id: id
        }
      })
    },
    async onLoad () {
      let res = await articleListAPI({
        channel_id: this.channel_id,
        timestamp: this.timestamp
      })
      // console.log(res)
      //   把得到的数据追加到list数组里面
      this.list.push(...res.data.data.results)
      //   讲时间戳换成发送请求后得到的新的时间戳
      this.timestamp = res.data.data.pre_timestamp
      this.loading = false
      if (this.timestamp == null) {
        this.finished = true
      }
    }
  }
}
</script>

<style lang="less">
.pic {
  width: 100%;
}
.date {
  span {
    font-size: 12px;
    color: #ccc;
  }
  span:nth-child(2) {
    margin: 0 5px;
  }
}
</style>
